package kevin.hbase.config;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HbaseConfig {
    @Value("${hbase.config.fileName:'hbase-site.xml'}")
    private String hbaseSiteFile;

    @Bean
    public Connection hbaseConnection() throws Exception {
        org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
        config.addResource(hbaseSiteFile);
        config = HBaseConfiguration.create(config);
        Connection connection = ConnectionFactory.createConnection(config);
        return connection;
    }
}
